package bakaLevel;

import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;

public class PlayerEvent implements Listener {

	@EventHandler(priority = EventPriority.HIGHEST)
	public static void onEntityDamage(EntityDamageByEntityEvent event) {
		// cause while all was humanentity
		if (!(event.getDamager() instanceof HumanEntity && event.getEntity() instanceof HumanEntity)) {
			return;
		}
		HumanEntity eVictim = (HumanEntity) event.getEntity();
		HumanEntity eDamager = (HumanEntity) event.getDamager();
		if (eDamager instanceof Player) {
			// Player damage other entity???
			// Check the entity is dead?
			if (event.getFinalDamage() > eVictim.getHealth()) {
				// WOW he is dead
				// is a player?
				//yes! player was hitting mosters
				if(eDamager instanceof Player && eVictim instanceof Monster)
				{
					PlayerPVEHandler.handle(event);
					return;
				}
				// nooooooo, he is pvp now
				else if (eDamager instanceof Player && eVictim instanceof Player) {
					PlayerPVPHandler.handle(event);
					return;
				}
			}
		}
	}
}
